import numpy as np
import matplotlib.pyplot as plt


N = 7
winnersplot = (142.6, 125.3, 62.0, 81.0, 145.6, 319.4, 178.1)
nomineesplot = (109.4, 94.8, 60.7, 44.6, 116.9, 62.5, 102.0)
ind = np.arange(N)
width = 0.35


fig, ax = plt.subplots()
# 第一个图
winner = ax.bar(ind, winnersplot, width, color='#ffad00')
# 第二个图
nominees = ax.bar(ind+width, nomineesplot, width, color='#9b3c38')

# 设置x轴
ax.set_xticks(ind+width)
# 重置x轴刻度值，同时将值倾斜15度
ax.set_xticklabels(('Best Picture', 'Director', 'Best Actor', 'Best Actress', 'Editing',
                    'Visual Effects', 'Cinematography'), rotation=15)
# 设置图例
ax.legend((winner[0], nominees[0]), ('Academy Award Winners', 'Academy Award Nominess'))


def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        hcap = '${}M'.format(str(height))
        # bar上增加标签
        ax.text(rect.get_x() + rect.get_width() / 2, height, hcap, ha='center', va='bottom', rotation='vertical')


# bar上打标签
autolabel(rects=winner)
autolabel(rects=nominees)

plt.show()
